from asyncio.windows_events import NULL
from ctypes import sizeof
from ensurepip import version
import socket
import os
import string
import time
import json
import random
import sys

print(sys.argv[1])  #sys.argv[1] 表示传入的第一个参数，既 hello
version = sys.argv[1]

# filename = "./app.bin"

filename = "./22.mp4"

filesize = os.path.getsize(filename)
f = open(filename, 'rb')
a = f.read()
count = 0

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 5679))

print('file Name' + filename, 'file Size' + str(filesize))

# 发送文件头信息
data1 = {
    'version': version,
    'name': "app.bin",
    'fileSize': filesize,
}
json = json.dumps(data1, sort_keys=True, indent=4, separators=(',', ': '))
print(json)
s.send(json.encode())

#等待服务器响应
s.recv(1024)
print('statr file data')

#发送文件体
s.send(a)
s.recv(1024)

input('if key out:\n')

s.close
